signature TRANSLATE =
sig
    type level
    type access			(* not the same as FRAME.access *)

    val outermost : level
    val newLevel : {parent : level,
		    name : Temp.label,
		    formals : bool list} -> level
    val formals : level -> access list
    val allocLocal : level -> bool -> access
end

structure Translate : TRANSLATE =
struct

  structure E = ErrorMsg
  structure F = MipsFrame
  structure M = Temp

  datatype level = Outermost of {frame : F.frame}
		 | FunLevel of {frame: F.frame, parent: level}

  type access = level * F.access

  fun newLevel {parent, name, formals}
      = FunLevel( {parent = parent, 
		frame = F.newFrame({name = name, formals = formals})} )


  val outermost = Outermost ({frame=F.newFrame({name=M.newlabel(),formals=[]})   }) 

(*Outermost({  F.newFrame({name=M.newlabel(),formals=[]})    }*)
 
  fun formals (Outermost {frame}) = nil
    | formals (level as FunLevel{frame,parent}) = 
       map (fn x => (level, x)) (F.formals(frame))

  fun allocLocal (level as Outermost{frame}) escape = 
      E.impossible " Impossible to allocate local Outermost level "
    | allocLocal (level as FunLevel{frame,parent}) escape = 
      		 let   val result = (level, F.allocLocal frame escape)
		 in 
		    result
		 end

      

end
